package com.whpost.service.wx.service;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whpost.service.dao.t.TRegionDao;
import com.whpost.service.dao.t.TXzjgDao;
import com.whpost.service.entity.t.TRegion;
import com.whpost.service.entity.t.TXzjg;
import com.whpost.service.entity.tools.ListInfo;
import com.whpost.service.entity.tools.PageInfo;
import com.whpost.service.entity.tools.ResultInfo;
import com.whpost.service.service.WxBaseServices;
import com.whpost.service.service.t.TApiNonceService;
import com.whpost.service.tools.ToolBean;
import com.whpost.service.tools.Url;
import com.whpost.service.wx.dao.WxBaomingMapper;
import com.whpost.service.wx.dao.WxBslxMapper;
import com.whpost.service.wx.dao.WxXxlyMapper;
import com.whpost.service.wx.entiy.BaoMingSubmitData;
import com.whpost.service.wx.entiy.WxBaoming;
import com.whpost.service.wx.entiy.WxBslx;
import com.whpost.service.wx.entiy.WxXxly;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by IntelliJ IDEA.
 *
 * @Author: Yin Zhuoyi
 * @Date: 2021/12/15 11:16
 */
@Service
public class JczlServices extends WxBaseServices<TXzjgDao, TXzjg> {

    public ResultInfo xzjgcx(String loginId, Map<String, Object> map) {
        JSONObject jsonObject = getData(map,loginId);
        if (StringUtils.isEmpty(loginId)){
            return new ResultInfo(500,"用户信息丢失！",null);
        }else{
            String curpage = "",pagesize="",cxmc="",parentId="",jb="";
            if (jsonObject.containsKey("curpage")) {
                curpage = jsonObject.getString("curpage");
            }
            if (jsonObject.containsKey("pagesize")) {
                pagesize = jsonObject.getString("pagesize");
            }
            if (jsonObject.containsKey("cxmc")) {
                cxmc = jsonObject.getString("cxmc");
            }
            if (jsonObject.containsKey("parentId")) {
                parentId = jsonObject.getString("parentId");
            }

            if (StringUtils.isEmpty(curpage)) curpage = "1";
            if (StringUtils.isEmpty(pagesize)) pagesize = "10";

            Page<TXzjg> page = new Page<>( Integer.parseInt(curpage),  Integer.parseInt(pagesize));

            ListInfo<TXzjg> TXzjgListInfo = new ListInfo<>();
            QueryWrapper<TXzjg> tXzjgQueryWrapper = new QueryWrapper<TXzjg>();

            if (!StringUtils.isEmpty(parentId)){
                tXzjgQueryWrapper.eq("pid",parentId);
            }
            if (!StringUtils.isEmpty(jb)){
                tXzjgQueryWrapper.eq("jb",jb);
            }

            if (!StringUtils.isEmpty(cxmc)){
                tXzjgQueryWrapper.like("name",cxmc);
            }else{
                tXzjgQueryWrapper.eq("1","1");
            }
            tXzjgQueryWrapper.orderByAsc("xh");

            IPage<TXzjg> TXzjgIPage = getBaseMapper().selectPage(page,tXzjgQueryWrapper);
            PageInfo pageInfo = new PageInfo();
            pageInfo.setTotal(TXzjgIPage.getTotal());
            pageInfo.setCurPage(TXzjgIPage.getCurrent());
            pageInfo.setPageSize(TXzjgIPage.getSize());
            pageInfo.setPageTotal(TXzjgIPage.getPages());

            TXzjgListInfo.setPageInfo(pageInfo);
            TXzjgListInfo.setListInfo(TXzjgIPage.getRecords());

            ResultInfo resultInfo = new ResultInfo(200, "成功返回！",TXzjgListInfo);
            return backRtn(resultInfo,loginId);
        }
    }
}
